package com.fdb.efp.cus.service.impl;

import com.fdb.efp.cus.service.dao.CusOrgEditDao;
import com.fdb.efp.cus.service.domain.CusOrgEdit;
import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.cus.service.facade.CusOrgEditService;
import com.fdb.efp.cus.service.vo.CusOrgEditVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * Service Impl: 服务实现
 *
 * @author gcb
 * @date 2020-11-03
 */
@Service("cusOrgEditService")
public class CusOrgEditServiceImpl implements CusOrgEditService, FrameworkService {

    private static Logger logger = LoggerFactory.getLogger(CusOrgEditServiceImpl.class);

    @Autowired
    private CusOrgEditDao cusOrgEditDao;

    /**
     * 新增数据
     *
     * @param cusOrgEditVo
     * @return
     */
    @Override
    public int insert(CusOrgEditVO cusOrgEditVo) {
        logger.debug("当前新增数据为:" + cusOrgEditVo.toString());
        int num = 0;
        try {
            CusOrgEdit cusOrgEdit = new CusOrgEdit();
            beanCopy(cusOrgEditVo, cusOrgEdit);
            num = cusOrgEditDao.insert(cusOrgEdit);
        } catch (Exception e) {
            logger.error("新增数据发生异常!", e);
            num = -1;
        }
        logger.debug("当前新增数据条数为:" + num);
        return num;
    }

    /**
     * 根据主键删除信息
     *
     * @param cusOrgEditVo
     * @return
     */
    @Override
    public int deleteByPk(CusOrgEditVO cusOrgEditVo) {
        logger.debug("当前删除数据条件为:" + cusOrgEditVo);
        int num = 0;
        try {
            CusOrgEdit cusOrgEdit = new CusOrgEdit();
            beanCopy(cusOrgEditVo, cusOrgEdit);
            num = cusOrgEditDao.deleteByPk(cusOrgEdit);
        } catch (Exception e) {
            logger.error("删除数据发生异常!", e);
            num = -1;
        }
        logger.debug("根据条件:" + cusOrgEditVo + "删除的数据条数为" + num);
        return num;
    }

    /**
     * 根据主键更新信息
     *
     * @param cusOrgEditVo
     * @return
     */
    @Override
    public int updateByPk(CusOrgEditVO cusOrgEditVo) {
        logger.debug("当前修改数据为:" + cusOrgEditVo.toString());
        int num = 0;
        try {
            CusOrgEdit cusOrgEdit = new CusOrgEdit();
            beanCopy(cusOrgEditVo, cusOrgEdit);
            num = cusOrgEditDao.updateByPk(cusOrgEdit);
        } catch (Exception e) {
            logger.error("修改数据发生异常!", e);
            num = -1;
        }
        logger.debug("根据条件:" + cusOrgEditVo + "修改的数据条数为" + num);
        return num;
    }

    /**
     * 根据主键查询详情
     *
     * @param inCusOrgEditVo
     * @return
     */
    @Override
    public CusOrgEditVO queryByPk(CusOrgEditVO inCusOrgEditVo) {
        logger.debug("当前查询参数信息为:" + inCusOrgEditVo);
        try {
            CusOrgEdit queryCusOrgEdit = new CusOrgEdit();
            beanCopy(inCusOrgEditVo, queryCusOrgEdit);
            CusOrgEdit queryRslCusOrgEdit = cusOrgEditDao.queryByPk(queryCusOrgEdit);
            if (Objects.nonNull(queryRslCusOrgEdit)) {
                return beanCopy(queryRslCusOrgEdit, new CusOrgEditVO());
            } else {
                logger.debug("当前查询结果为空!");
            }
        } catch (Exception e) {
            logger.error("查询数据发生异常!", e);
        }
        return null;
    }

    @Override
    public CusOrgEditVO queryByOrgNo(CusOrgEditVO cusOrgEditVO) {
        logger.debug("当前查询参数信息为:" + cusOrgEditVO);
        try {
            CusOrgEdit queryCusOrgEdit = new CusOrgEdit();
            beanCopy(cusOrgEditVO, queryCusOrgEdit);
            CusOrgEdit queryRslCusOrgEdit = cusOrgEditDao.queryByOrgNo(queryCusOrgEdit);
            if (Objects.nonNull(queryRslCusOrgEdit)) {
                return beanCopy(queryRslCusOrgEdit,new CusOrgEditVO());
            } else {
                logger.debug("当前查询结果为空!");
            }
        } catch (Exception e) {
            logger.error("查询数据发生异常!", e);
        }
        return new CusOrgEditVO();
    }


}
